package ch.unisi.inf.java.project.riskbami.model;


/**
 * FortifyCommand is an extension of GenericCommand.
 * Provide the implementation of a commands that is responsible to fortify
 * some territories
 * 
 * @author minellir@lu.unisi.ch
 * @author babazadm@lu.unisi.ch
 */
public final class FortifyCommand extends GenericCommand
{
    private final Country source;
    private final Country destination;
    private final int howMany;
    private final Player player;
    
    /**
     * The contructor for the class FortifyCommand
     * 
     * @param game The actual game
     * @param src The country from which the armies moves
     * @param dest The country in which the armies moves
     * @param howMany The number of armies to moves
     */
    public FortifyCommand(final Game game, final Country src, final Country dest, final int howMany) {
        super(game);
        source = src;
        destination = dest;
        this.howMany = howMany;
        this.player = game.getCurrentPlayer();
    }
    
    /**
     * canExecute verify whether the FortifyCommand could be executed
     * 
     * @return boolean
     */
    public final boolean canExecute() {
        if(source.getNumberOfArmies() > 1 && game.getTurnPhase() == 2 || game.getTurnPhase() == 3) {
            return true;
        }
        else return false;
    }
    
    /**
     * execute is responsible to execute the given FortifyCommand.
     */
    public final void execute() {
        if(game.getTurnPhase() == 2){
            game.switchNextPhase();
        }
        player.fortify(source, destination, howMany);
        game.switchNextPhase();
        game.switchNextPlayer();
    }
}
